#include<iostream>
#include<vector>
#include<string>
#include<unordered_map>
#include<unordered_set>
#include<algorithm>

using namespace std;

class Solution{
public:
    int longestConsecutive(vector<int> & nums){
        
        int max_length = 0;

        unordered_set<int> num_set(nums.begin(), nums.end());
        for(int x : num_set){
            // 如果找不到比他小1的，那它就是起点
            if(num_set.find(x - 1) == num_set.end()){
                int current_length = 1; // 设置初始长度为1
                int current_num = x;
                // cout << x <<endl;

                while(num_set.find(current_num + 1) != num_set.end()){
                    current_length ++ ;
                    current_num ++ ;
                }
                max_length = max(max_length, current_length);
            }
        }
        return max_length;

    }

};


int main(){
    Solution solution;
    vector<int> nums = {1, 0, 1, 2};

    int max_length = solution.longestConsecutive(nums);

    cout << "max length is " << max_length << endl;

}

